package com.example.house.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.house.R
import com.example.house.entity.HouseEntityItem
import com.example.house.entity.MyHouseEntity

class HouseAdapter:BaseQuickAdapter<MyHouseEntity, BaseViewHolder>(R.layout.item_earahouse) {

    override fun convert(holder: BaseViewHolder, item: MyHouseEntity) {
        holder.setText(R.id.tv01,""+item.dong+"栋")
        holder.setText(R.id.hourse_area,""+item.area+"m²")
        val recyclerView = holder.getView<RecyclerView>(R.id.rv_01)
        val imageView = holder.getView<ImageView>(R.id.more01)
        imageView.setOnClickListener {
            if (recyclerView.visibility == View.GONE) {
                recyclerView.visibility = View.VISIBLE
                imageView.setImageResource(R.drawable.ic_up)
            } else {
                recyclerView.visibility = View.GONE
                imageView.setImageResource(R.drawable.ic_down)
            }
        }
        var houseRvAdpter=HouseRvAdapter()
        recyclerView.layoutManager=GridLayoutManager(context,2)
        recyclerView.adapter=houseRvAdpter
        houseRvAdpter.addChildClickViewIds(R.id.status)
        houseRvAdpter.data.clear()
        houseRvAdpter.addData(item.list)
    }
}
class HouseRvAdapter:BaseQuickAdapter<HouseEntityItem,BaseViewHolder>(R.layout.item_house) {
    override fun convert(helper: BaseViewHolder, item: HouseEntityItem) {
        helper.setText(R.id.room,"${item.id}室")
        helper.setText(R.id.qiye,item.enterpriseName)
        helper.setText(R.id.mianji,"${item.area}m²")
        val tv = helper.getView<TextView>(R.id.status)
        if(item.rented){
            tv.setText("出租")
            tv.setBackgroundResource(R.drawable.bg_green)
            tv.setTextColor(R.drawable.bg_green)
            tv.setTextColor(tv.resources.getColor(R.color.color_green))
        }else{
            tv.setText("空置")
            tv.setBackgroundResource(R.drawable.bg_blue111)
            tv.setTextColor(R.drawable.bg_blue111)
            tv.setTextColor(tv.resources.getColor(R.color.color_blue))
        }

    }
}